<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>递归</title>
</head>
<body>
<script>
    //累加
    function getSum(num) {
        if(num <=1){
            return 1
        }
        return num+getSum(num-1)
    }
    console.log(getSum(5));
    //所有的位置数字相加
    function getEverySum(num) {
        num = Math.abs(num);
        if(num<10){
            return num;
        }
        return num%10 + getEverySum(parseInt(num/10))
    }
    console.log(getEverySum(-547))
    //斐波那契额数列
    function getFib(x) {
        if(x==1||x==2){
            return 1
        }
        return getFib(x-1)+getFib(x-2)
    }
    console.log(getFib(12))
</script>
</body>
</html>